//
//  HForwardViewController.swift
//  GZWeibo007
//
//  Created by 何梓杰 on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
import SVProgressHUD
class HForwardViewController: UIViewController {
    
    var status:CZStatus?

    override func viewDidLoad() {
        super.viewDidLoad()
        prepareUI()
        view.backgroundColor = UIColor.whiteColor()
        self.title = "转发";
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: UIBarButtonItemStyle.Plain, target: self, action: "closeModal")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "转发", style: UIBarButtonItemStyle.Plain, target: self, action: "sentMessage")
        
        self.modalPresentationStyle = UIModalPresentationStyle.FormSheet
    }
    
    func closeModal() {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    
    func sentMessage() {
//        textView.text, id: (status?.id)!, error: nil
        CZNetworkTool.sharedInstance.repostStatus(textView.text, id: (status?.id)!, error: nil) { () -> Void in
            SVProgressHUD.dismiss()
            self.closeModal()
        }
        SVProgressHUD.showWithStatus("正在发送评论")
    }
//    private func prepareUI() {
//        self.view.addSubview(textView)
//        
//        textView.translatesAutoresizingMaskIntoConstraints = false
//        
//        self.view.addConstraint(NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
//        
//        self.view.addConstraint(NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 300))
//        
//        self.view.addConstraint(NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: self.view.bounds.width))
//    }

    private func prepareUI() {
        self.view.addSubview(textView)
        
        textView.translatesAutoresizingMaskIntoConstraints = false
        
        self.view.addConstraint(NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        
        self.view.addConstraint(NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 300))
        
        self.view.addConstraint(NSLayoutConstraint(item: textView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: self.view.bounds.width))
    }

    lazy var textView : UITextView = {
        let textView = UITextView()
//        textView.backgroundColor = UIColor.redColor()
        return textView
    }()
    
}
